home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / What's New? / Technical Documentaion / Macintosh Technotes and Q&As / technotes / tn / 1076_MsgTest.hqx / MsgTest / PCMsgTst / MSG.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-08-29  |  4.2 KB  |  166 lines

  1. ; --------------------------------------------------------------------------------------
  2. ;
  3. ; MESG.ASM
  4. ; By Ben Manuto
  5. ;
  6. ; Assembly glue to hook into the Messaging system Interface.
  7. ;
  8. ; c.1996, by Apple Computer, Inc. All rights reserved.
  9. ;
  10. ; --------------------------------------------------------------------------------------
  11.  
  12. INCLUDE MSG.INC
  13.  
  14.  
  15. MsgAvailable    PROTO FAR C
  16. MsgRegister        PROTO FAR C  msgSel:DWORD, msgCount:WORD, msgCmmd:WORD 
  17. MsgSend            PROTO FAR C  msgPBlk:DWORD
  18.  
  19. MsgInstHandler    PROTO FAR C  msgRecElem:DWORD
  20. MsgRmvHandler    PROTO FAR C  msgRecElem:DWORD
  21.  
  22. MsgReceive        PROTO FAR C     msgPBlk:DWORD
  23. MsgHandler        PROTO FAR C
  24.  
  25. _TEXT SEGMENT PUBLIC 'CODE'
  26. .486
  27.  
  28. ; --------------------- DATA ------------------------
  29.  
  30. msgReceiveSegment        WORD ?                 ; gobal to msgPBlk (msgReceiveSegment:msgReceiveOffset) 
  31. msgReceiveOffset        WORD ?
  32.  
  33.  
  34.  
  35. ;------------------------------------------------------------------------------
  36.  
  37. MsgAvailable PROC FAR C 
  38.  
  39.    mov   ah,rsIsAvailable
  40.    int   MsgCall
  41.  
  42.    ret   
  43.  
  44. MsgAvailable    ENDP 
  45.  
  46.  
  47. ;------------------------------------------------------------------------------
  48.  
  49. MsgRegister PROC FAR C  msgSel:DWORD, msgCount:WORD, msgCmmd:WORD
  50.  
  51.    mov   ebx,msgSel
  52.    mov   cx,msgCount
  53.    mov   ah,rsRegisterMessage
  54.    int   MsgCall
  55.    
  56.    mov   dx,bx
  57.    mov   bx,msgCmmd
  58.    mov   [bx],dx
  59.    ret
  60.  
  61.  
  62. MsgRegister ENDP
  63.  
  64.  
  65. ;------------------------------------------------------------------------------
  66.  
  67. MsgSend PROC FAR C  msgPBlk:DWORD
  68.  
  69.     les   bx,msgPBlk                                ; Load the msgPBlk into es:bx
  70.     mov   ah,rsSendMessage
  71.     int   MsgCall                                     ; Send it to the Mac.
  72.  
  73.     ret
  74.  
  75. MsgSend   ENDP
  76.  
  77.  
  78. ;------------------------------------------------------------------------------
  79.  
  80. MsgInstHandler  PROC FAR C  msgRecElem:DWORD
  81.  
  82.     les  bx,msgRecElem
  83.     mov  ah,rsInstallMsgHandler
  84.     int  MsgCall
  85.    
  86.     sub  ax,ax
  87.     ret
  88.  
  89. MsgInstHandler  ENDP
  90.  
  91.  
  92. ;------------------------------------------------------------------------------
  93.  
  94. MsgRmvHandler  PROC FAR C  msgRecElem:DWORD
  95.  
  96.    mov   ah,rsRemoveMsgHandler               
  97.    les   bx,msgRecElem                      ; load the msgRecElem into es:bx
  98.    int   MsgCall                               ; Call the message system to remove it.
  99.  
  100.    sub   ax,ax
  101.    ret
  102.  
  103. MsgRmvHandler  ENDP
  104.     
  105.     
  106. ;------------------------------------------------------------------------------
  107.  
  108. MsgReceive PROC FAR C    msgPBlk:DWORD
  109.  
  110.         les        bx,msgPBlk                        ; Load MsgPBlk into es:bx.
  111.         mov     es:MsgPBlk.msgResult[BX],1        ; Set it to busy.
  112.         
  113.         mov        cs:[msgReceiveSegment], 0         ; Set our global to NULL.
  114.         mov        cs:[msgReceiveOffset], 0
  115.         
  116.         cmp     es:MsgPBlk.msgBuffer[bx], 0     ; Is the msgBuffer NULL?
  117.         jz        exit                               ; If so, get out.
  118.  
  119.         mov     cs:[msgReceiveOffset],bx        ; If not, save the ptr for the receiver routine.
  120.         mov        bx,es
  121.         mov     cs:[msgReceiveSegment],bx    
  122.         xor     ax,ax                           
  123.     
  124.     exit:    
  125.         ret
  126.         
  127. MsgReceive      ENDP
  128.  
  129.  
  130. ;------------------------------------------------------------------------------
  131. ; If there is data attached to this message, then return (in es:bx) a pointer to MsgPBlock.
  132. ; If the message is contained solely in param1 and param2 (ie no buffer) return es:bx as NULL.
  133.        
  134.  
  135. MsgHandler PROC FAR C
  136.    
  137.         cmp        ax, ds:MsgRecElem.cmdBase[di]    ; compare current msgCmd and cmdBaseID
  138.         jg        setAck                            ; Set the Ack flag and bail..
  139.         
  140.         mov        bx, cs:msgReceiveSegment        ; Check msgReceive (our MsgPBlk) for null?
  141.         or        bx, cs:msgReceiveOffset
  142.         jz        nope                            ; if null, bail.
  143.         
  144.         mov        bx, cs:msgReceiveSegment          ; otherwise, load es:bx with msgReceive pointer
  145.         mov        es, bx
  146.         mov        bx, cs:msgReceiveOffset    
  147.         retf                                       ; return
  148.     
  149.     setAck:
  150.         les        bx, ds:MsgRecElem.userData[di]        ; load ES:BX with a pointer to the AckInfo structure.
  151.         mov        es:AckInfo.bytesReceived[bx], ecx    ; load bytesRecevied with ECX (param1).
  152.         mov        es:AckInfo.ackReceived[bx], 1        ; Mark that the ack was received.
  153.             
  154.     nope:
  155.         xor        bx, bx                           ; Clear BX.           
  156.         mov        es, bx                             ; Put bx in es.
  157.         retf
  158.         
  159. MsgHandler         ENDP
  160.  
  161.  
  162. _TEXT ENDS
  163.  
  164. END
  165.  
  166.